package com.pignest.hotel.ui.reception;

import org.zkoss.zk.ui.Executions;

import com.pignest.framework.util.Log;
import com.pignest.hotel.beans.Room;
import com.pignest.hotel.definition.RoomStatus;
import com.pignest.hotel.spring.Services;
import com.pignest.hotel.system.Config;
import com.pignest.hotel.system.Logic;
import com.pignest.hotel.ui.room.RoomHistogram;
import com.pignest.hotel.ui.room.RoomView;

/**
 * 团队快速入住图房态图
 * 
 * @author Jude
 */
public class QuickLivingHistogram extends RoomHistogram {
	private static final long serialVersionUID = -387180817069233960L;

	public QuickLivingHistogram() {
		super();
		setLineCapacity(Config.getLineCapacityOfReception());
		setShowFlags(RoomView.SHOW_ALL);
		filterStatuses.add(RoomStatus.EMPTY_CLEAN.getName());
		filterStatuses.add(RoomStatus.EMPTY_NIGHT.getName());
	}
	
	public void onLiving(String roomId) {
		Room room = Services.getRoomService().getRoom(roomId);
		if (Logic.canLiving(room))
			onLiving(room);
	}
	
	/** 入住 */
	private void onLiving(Room room) {
		final LivingWindow win = (LivingWindow) Executions.createComponents(
				"/modules/reception/livingWindow.zul", null, null);
		win.setClosable(true);
		win.setRoom(room);
		try {
			win.doModal();
			if (win.isSuccess()) {
				RoomView rv = getView(room.getId());
				if (rv != null)
					rv.updateRoom();
			}
		} catch (Exception e) {
			Log.e(e);
		}
	}
	
}
